//
//  Association+Extension.swift
//  Poetry
//
//  Created by cheyongzi on 2023/12/14.
//

import Foundation
import ObjectiveC

public final class ObjectAssociation<T: Any>{
    private let policy: objc_AssociationPolicy

        public init(_ policy: objc_AssociationPolicy = .OBJC_ASSOCIATION_RETAIN_NONATOMIC) {
            self.policy = policy
        }
        public subscript(index: Any) -> T? {
            get { return objc_getAssociatedObject(index, Unmanaged.passUnretained(self).toOpaque()) as? T }
            set { objc_setAssociatedObject(index, Unmanaged.passUnretained(self).toOpaque(), newValue, policy) }
        }
}
